<!DOCTYPE html>
<html>
 <head> 
  	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<meta charset="UTF-8" name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>  
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="format-detection" content="telephone=no">
	<title>整体分析</title> 
 </head> 
 <body style="margin:0px;padding:0px;">
  <div id="bbtLineChart" style="border-top:1px solid #ccc;" onClick="window.location.href='bbtChart.html'"></div> 
  <div style="text-align:center; margin-left:auto;">
    <div id="mensesBarChart" style="width:49%;border-top:1px solid #ccc;display:inline-block" onClick="window.location.href='mensesChart.html'"></div> 
    <div id="mucusBarChart" style="width:49%;border-top:1px solid #ccc;display:inline-block" onClick="window.location.href='mucusChart.html'"></div> 
  </div> 
  
  <!-- <script type="text/javascript" charset="utf-8" src="js/cordova.js"></script> -->
  <script type="text/javascript" src="js/common/echarts.js"></script>
  <script type="text/javascript" src="js/common/mapUtil.js"></script>
  <script type="text/javascript" src="js/overview/initOverviewChartData.js"></script> 
  <script type="text/javascript" src="js/overview/drawOverviewChart.js"></script> 
  <script type="text/javascript" src="js/common/dateUtil.js"></script> 	 
  <script type="text/javascript" src="js/common/periodUtil.js"></script>
 
  <script type="text/javascript">
  
    var customerDataJSONArray;
    var customerDataJSONArrayLen;
    
    var customerDate;
	var customerPeriod;
	var customerTemperature;
	var heart;
	var moon;
	var medicine;
	var drink;
	var plane;
	var mucus;
	
	var customerDateStr;
	var customerDateTemperatureStr;
	var customerDatePolishedTemperatureStr;
	var customerDatePeriodStr;
	var customerDateHeartStr;
	var customerDateMoonStr;
	var customerDateMedicineStr;
	var customerDateDrinkStr;
	var customerDatePlaneStr;
	var customerDateMucusStr;
	
    var customerDateTemperatureMap = new Map();
    var customerDatePolishedTemperatureMap = new Map();
    var customerDateMucusMap = new Map();
    var customerDatePeriodMap = new Map();

    var customerDateArray = new Array();
    var customerTemperatureArray = new Array();
    var customerDatePolishedTemperatureArray = new Array();
    
     /*
			real模拟 var DataStr = '[{"date": "2015-1-1", 
  								"period": "yjq", 
  								"temperature": "37.5", 
  								"heart":"yes", 
  								"moon":"no",
  								"drink":"no",
  								"medicine":"yes", 
  								"plane":"no", 
  								"mucus":"3"},
							...]';
   */
  
  /* 
  setTimeout(generateCustomerDataStr, 200);  //onload="generateCustomerDataStr()"
  
  function generateCustomerDataStr(){      
      getAnalysisResults("overviewChart", function(customerDateDataStr) {
            showOverviewChart(customerDateDataStr);
      });
  }
  
  function getAnalysisResults(str, callback) {
      cordova.exec(callback, function(err) {
                   callback('get Analysis Results Error! ');
                   }, "GetAnalysisResultsService", "getAnalysisResultsAction", [str]);
  }
  */
customerDataJSONStr = "["
                    + "{\"date\": \"2015-12-15\", "
                    + "\"period\": \"yjq\", "
                    + "\"temperature\": \"37.5\", "
                    + "\"heart\":\"yes\", "
                    + "\"moon\":\"no\",\"drink\":\"no\", "
                    + "\"medicine\":\"yes\", "
                    + "\"plane\":\"no\", "
                    + "\"mucus\":\"3\""
                    + "},"
                    + "{\"date\": \"2015-12-16\", "
                    + "\"period\": \"lpq\", "
                    + "\"temperature\": \"38.5\", "
                    + "\"heart\":\"no\", "
                    + "\"moon\":\"no\",\"drink\":\"yes\", "
                    + "\"medicine\":\"yes\", "
                    + "\"plane\":\"no\", "
                    + "\"mucus\":\"4\""
                    + "},"
                    + "{\"date\": \"2015-12-17\", "
                    + "\"period\": \"plq\", "
                    + "\"temperature\": \"-\", "
                    + "\"heart\":\"no\", "
                    + "\"moon\":\"no\",\"drink\":\"yes\", "
                    + "\"medicine\":\"yes\", "
                    + "\"plane\":\"no\", "
                    + "\"mucus\":\"4\""
                    + "},"
                    + "{\"date\": \"2015-12-18\", "
                    + "\"period\": \"htq\", "
                    + "\"temperature\": \"37.5\", "
                    + "\"heart\":\"yes\", "
                    + "\"moon\":\"no\",\"drink\":\"no\", "
                    + "\"medicine\":\"yes\", "
                    + "\"plane\":\"no\", "
                    + "\"mucus\":\"3\""
                    + "},"
                    + "{\"date\": \"2015-12-19\", "
                    + "\"period\": \"yjq\", "
                    + "\"temperature\": \"37.5\", "
                    + "\"heart\":\"yes\", "
                    + "\"moon\":\"no\",\"drink\":\"no\", "
                    + "\"medicine\":\"yes\", "
                    + "\"plane\":\"no\", "
                    + "\"mucus\":\"3\""
                    + "}"
                    + "]";
                showOverviewChart(customerDataJSONStr);
                  
  //showOverviewChart(window.CustomerData.getCustomerDataJSONStr());
	
  function showOverviewChart(customerDateDataStr){
  	initCustomerDataIntoJSON(customerDateDataStr);
  	initCustomerDataIntoArrayMap(customerDateDataStr);
  	clearLocalCustomerDateData();
    saveCustomerDateDataStr2Local(customerDateDataStr);
    
  	initOverviewChartData(customerDateDataStr);
  	initOverviewChartZone();
    setEChartConfig();
	drawOverviewChart();
  }
  
  function initCustomerDataIntoJSON(DataStr){  	
  	customerDataJSONArray = JSON.parse(DataStr);
  	customerDataJSONArrayLen = customerDataJSONArray.length;
  }
  
  function initCustomerDataIntoArrayMap(customerDateDataStr){
  	for(var i = 0; i < customerDataJSONArrayLen; i ++){		
  		getJSONArrayCustomerDateData(i);

  		customerDateArray[i] = customerDate;
    	customerTemperatureArray[i] = customerTemperature;
  		customerDateTemperatureMap.put(customerDate, customerTemperature);
        customerDatePeriodMap.put(customerDate, customerPeriod);
        customerDateMucusMap.put(customerDate, mucus);
  	}

  	initCustomerDatePolishedTemperatureArray();
  	initCustomerDatePolishedTemperatureMap();
  }

  function initCustomerDatePolishedTemperatureArray(){
  	var firstValidTemperatureDate = getFirstValidTemperatureDate(customerDateArray.toString());

    if(firstValidTemperatureDate == "-"){//没有任何数据
    	customerDatePolishedTemperatureArray = customerTemperatureArray;
    }else{
        for(var i = 0; i< customerDataJSONArrayLen; i++){
            if(customerTemperatureArray[i] == "-" &&
                        compareDateStr(customerDateArray[i],getCurrentDateStr()) &&
                        compareDateStr(firstValidTemperatureDate, customerDateArray[i])){

                var previousValidDateStr =  getPreviousValidBBTDate(i, customerDateArray.toString());
                var nextValidDateStr = getNextValidBBTDate(i, customerDateArray.toString());

                if(previousValidDateStr == "-" || nextValidDateStr == "-")
                    customerDatePolishedTemperatureArray[i] = "-";
                else{
                    customerDatePolishedTemperatureArray[i] = getPolishedTemperature(previousValidDateStr, customerDateArray[i], nextValidDateStr);
                }
            }else{
                customerDatePolishedTemperatureArray[i] = customerTemperatureArray[i];
            }
        }
    }
  }

  function initCustomerDatePolishedTemperatureMap(){
  	for(var i = 0; i < customerDataJSONArrayLen; i ++){
  		var customerDate = customerDataJSONArray[i].date;
  		customerDatePolishedTemperatureMap.put(customerDate, customerDatePolishedTemperatureArray[i]);
  	}
  }

  function clearLocalCustomerDateData(){
  	localStorage.clear();
  }
  
  function saveCustomerDateDataStr2Local(customerDateDataStr){
  	customerDateStr = "["; 	 	  	 
  	customerDateTemperatureStr = "[";
  	customerDatePolishedTemperatureStr = "[";
	customerDatePeriodStr = "[";
	customerDateHeartStr = "[";
	customerDateMoonStr = "[";
	customerDateMedicineStr = "[";
	customerDateDrinkStr = "[";
	customerDatePlaneStr = "[";
	customerDateMucusStr = "[";
  	
  	for(var i = 0; i < customerDataJSONArrayLen; i ++){
		getJSONArrayCustomerDateData(i);	
  		
  		customerDateStr += '{"date":"'+ customerDate + '"}';  		
  		if( i != customerDataJSONArrayLen - 1)
  			customerDateStr += ",";
  		
  		customerDateTemperatureStr += '{"date":"'+ customerDate + '", "temperature":"' + customerTemperature + '"}';  		
  		if( i != customerDataJSONArrayLen - 1)
  			customerDateTemperatureStr += ",";

  		customerDatePolishedTemperatureStr += '{"date":"'+ customerDate + '", "temperature":"' + customerDatePolishedTemperatureArray[i] + '"}';
  		if( i != customerDataJSONArrayLen - 1)
  			customerDatePolishedTemperatureStr += ",";
  		
  		customerDatePeriodStr += '{"date":"'+ customerDate + '", "period":"' + customerPeriod + '"}';
  		if( i != customerDataJSONArrayLen - 1)
  			customerDatePeriodStr += ",";
  			
  		customerDateHeartStr += '{"date":"'+ customerDate + '", "heart":"' + heart + '"}';
  		if( i != customerDataJSONArrayLen - 1)
  			customerDateHeartStr += ",";
  		
  		customerDateMoonStr += '{"date":"'+ customerDate + '", "moon":"' + moon + '"}';
  		if( i != customerDataJSONArrayLen - 1)
  			customerDateMoonStr += ",";
  			
  		customerDateMedicineStr += '{"date":"'+ customerDate + '", "medicine":"' + medicine + '"}';
  		if( i != customerDataJSONArrayLen - 1)
  			customerDateMedicineStr += ",";
  		
  		customerDateDrinkStr += '{"date":"'+ customerDate + '", "drink":"' + drink + '"}';
  		if( i != customerDataJSONArrayLen - 1)
  			customerDateDrinkStr += ",";
  			
  		customerDatePlaneStr += '{"date":"'+ customerDate + '", "plane":"' + plane + '"}';
  		if( i != customerDataJSONArrayLen - 1)
  			customerDatePlaneStr += ",";
  		
  		customerDateMucusStr += '{"date":"'+ customerDate + '", "mucus":"' + mucus + '"}';
  		if( i != customerDataJSONArrayLen - 1)
  			customerDateMucusStr += ",";
  	} 
  	
  	customerDateStr += "]";
  	customerDateTemperatureStr += "]";
  	customerDatePolishedTemperatureStr += "]";
  	customerDatePeriodStr += "]";
  	customerDateHeartStr += "]";
  	customerDateMoonStr += "]";
  	customerDateMedicineStr += "]";
  	customerDateDrinkStr += "]";
  	customerDatePlaneStr += "]";
  	customerDateMucusStr += "]";

  	saveCustomerData2Local("customerDateKey", customerDateStr);
  	saveCustomerData2Local("customerDateTemperatureKey", customerDateTemperatureStr);
  	saveCustomerData2Local("customerDatePolishedTemperatureKey", customerDatePolishedTemperatureStr);
  	saveCustomerData2Local("customerDatePeriodKey", customerDatePeriodStr);
  	saveCustomerData2Local("customerDateHeartKey", customerDateHeartStr);
  	saveCustomerData2Local("customerDateMoonKey", customerDateMoonStr);
  	saveCustomerData2Local("customerDateMedicineKey", customerDateMedicineStr);
  	saveCustomerData2Local("customerDateDrinkKey", customerDateDrinkStr);
  	saveCustomerData2Local("customerDatePlaneKey", customerDatePlaneStr);
  	saveCustomerData2Local("customerDateMucusKey", customerDateMucusStr);
  	saveCustomerData2Local("customerDateDataStrKey", customerDateDataStr);
  	saveCustomerData2Local("customerDataJSONArrayLenKey", customerDataJSONArrayLen);
  }

  function getJSONArrayCustomerDateData(i){
  		customerDate = customerDataJSONArray[i].date;
		customerPeriod = customerDataJSONArray[i].period;
  		customerTemperature = customerDataJSONArray[i].temperature;  		
  		heart = customerDataJSONArray[i].heart;
  		moon = customerDataJSONArray[i].moon;
  		medicine = customerDataJSONArray[i].medicine;
  		drink = customerDataJSONArray[i].drink;  		
  		plane = customerDataJSONArray[i].plane;
  		mucus = customerDataJSONArray[i].mucus;
  }

  function saveCustomerData2Local(key, value){
   	localStorage.setItem(key, value);
  }
  
    </script>  
 </body>
</html>